/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.swt.mto.thithu.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.util.PortalUtil;

import com.swt.mto.thithu.service.ResultLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author tuan.nguyen
 */
public class ResultClp extends BaseModelImpl<Result> implements Result {
	public ResultClp() {
	}

	public Class<?> getModelClass() {
		return Result.class;
	}

	public String getModelClassName() {
		return Result.class.getName();
	}

	public long getPrimaryKey() {
		return _resultId;
	}

	public void setPrimaryKey(long primaryKey) {
		setResultId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_resultId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("resultId", getResultId());
		attributes.put("quizId", getQuizId());
		attributes.put("userId", getUserId());
		attributes.put("userName", getUserName());
		attributes.put("numSentenceCorrect", getNumSentenceCorrect());
		attributes.put("totalSentence", getTotalSentence());
		attributes.put("score", getScore());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long resultId = (Long)attributes.get("resultId");

		if (resultId != null) {
			setResultId(resultId);
		}

		Long quizId = (Long)attributes.get("quizId");

		if (quizId != null) {
			setQuizId(quizId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		String userName = (String)attributes.get("userName");

		if (userName != null) {
			setUserName(userName);
		}

		Integer numSentenceCorrect = (Integer)attributes.get(
				"numSentenceCorrect");

		if (numSentenceCorrect != null) {
			setNumSentenceCorrect(numSentenceCorrect);
		}

		Integer totalSentence = (Integer)attributes.get("totalSentence");

		if (totalSentence != null) {
			setTotalSentence(totalSentence);
		}

		Double score = (Double)attributes.get("score");

		if (score != null) {
			setScore(score);
		}
	}

	public long getResultId() {
		return _resultId;
	}

	public void setResultId(long resultId) {
		_resultId = resultId;
	}

	public long getQuizId() {
		return _quizId;
	}

	public void setQuizId(long quizId) {
		_quizId = quizId;
	}

	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public String getUserName() {
		return _userName;
	}

	public void setUserName(String userName) {
		_userName = userName;
	}

	public int getNumSentenceCorrect() {
		return _numSentenceCorrect;
	}

	public void setNumSentenceCorrect(int numSentenceCorrect) {
		_numSentenceCorrect = numSentenceCorrect;
	}

	public int getTotalSentence() {
		return _totalSentence;
	}

	public void setTotalSentence(int totalSentence) {
		_totalSentence = totalSentence;
	}

	public double getScore() {
		return _score;
	}

	public void setScore(double score) {
		_score = score;
	}

	public BaseModel<?> getResultRemoteModel() {
		return _resultRemoteModel;
	}

	public void setResultRemoteModel(BaseModel<?> resultRemoteModel) {
		_resultRemoteModel = resultRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			ResultLocalServiceUtil.addResult(this);
		}
		else {
			ResultLocalServiceUtil.updateResult(this);
		}
	}

	@Override
	public Result toEscapedModel() {
		return (Result)Proxy.newProxyInstance(Result.class.getClassLoader(),
			new Class[] { Result.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		ResultClp clone = new ResultClp();

		clone.setResultId(getResultId());
		clone.setQuizId(getQuizId());
		clone.setUserId(getUserId());
		clone.setUserName(getUserName());
		clone.setNumSentenceCorrect(getNumSentenceCorrect());
		clone.setTotalSentence(getTotalSentence());
		clone.setScore(getScore());

		return clone;
	}

	public int compareTo(Result result) {
		long primaryKey = result.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		ResultClp result = null;

		try {
			result = (ResultClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = result.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(15);

		sb.append("{resultId=");
		sb.append(getResultId());
		sb.append(", quizId=");
		sb.append(getQuizId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", userName=");
		sb.append(getUserName());
		sb.append(", numSentenceCorrect=");
		sb.append(getNumSentenceCorrect());
		sb.append(", totalSentence=");
		sb.append(getTotalSentence());
		sb.append(", score=");
		sb.append(getScore());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(25);

		sb.append("<model><model-name>");
		sb.append("com.swt.mto.thithu.model.Result");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>resultId</column-name><column-value><![CDATA[");
		sb.append(getResultId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>quizId</column-name><column-value><![CDATA[");
		sb.append(getQuizId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userName</column-name><column-value><![CDATA[");
		sb.append(getUserName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>numSentenceCorrect</column-name><column-value><![CDATA[");
		sb.append(getNumSentenceCorrect());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>totalSentence</column-name><column-value><![CDATA[");
		sb.append(getTotalSentence());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>score</column-name><column-value><![CDATA[");
		sb.append(getScore());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _resultId;
	private long _quizId;
	private long _userId;
	private String _userUuid;
	private String _userName;
	private int _numSentenceCorrect;
	private int _totalSentence;
	private double _score;
	private BaseModel<?> _resultRemoteModel;
}